package com.fcl.blog.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.GetMapping;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * @Author 付
 * @Date 2023/10/14 12:46
 * @Version 1.0
 * @description
 * @since 1.0
 */

@Configuration
public class SwaggerConfig {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .host("116.62.151.168")
                .select()
                /**
                 * RequestHandlerSelectors.basePackage("com.fcl.library.controller") 扫描指定包
                 * RequestHandlerSelectors.any() 扫描所有
                 * RequestHandlerSelectors.none() 不扫描
                 * RequestHandlerSelectors.withClassAnnotation(RequestMapping.class) 扫描类上的注解RequestMapping.class
                 * RequestHandlerSelectors.withMethodAnnotation(GetMapping.class)  扫描方法上的注解
                 */
                .apis(RequestHandlerSelectors.withMethodAnnotation(GetMapping.class))
                // 过滤路径,只扫描controller下面路径/user 的所有请求
                .paths(PathSelectors.any())
                .build()
                // 设置不开启，默认是开启的
                .enable(true);
    }
    public ApiInfo apiInfo(){
        Contact concat = new Contact("乘凉","116.62.151.168","19923807615@163.com");
//         作者信息
        return new ApiInfo(
                "图书管系统",
                "这是一款对于图书管理的系统，可以用该系统完成图书的记录、借阅等相关操作",
                "1.0",
                "urn:tos",
                concat,
                "null",
                "null",
                new ArrayList());
    }
}
